package com.jeesite.modules.dataScreen.web;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.jeesite.modules.dataScreen.dao.themedb.ThemeDbDao;
import com.jeesite.modules.dataScreen.web.vo.Result;
import com.jeesite.modules.dataScreen.web.vo.ShuiluVo;
import com.jeesite.modules.dataScreen.web.vo.ZongheVo;
import com.jeesite.modules.dataScreen.web.vo.ZongheVo.G.GG;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author: zhaosenlin
 * @date: 2024/5/14 14:08
 */
@RestController
@Api(tags = "综合概览接口")
@RequestMapping("/zonghe")
@Slf4j
public class ZongheApi extends BaseController {

    @Resource
    ThemeDbDao themeDbDao;
    @Resource
    ShuiluApi shuiluApi;

    @ApiOperation("综合概览-成渝双城经济圈")
    @GetMapping("cydcjjq")
    public Result<ZongheVo.B> cydcjjq() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-成渝双城经济圈");
        ZongheVo.B b = new ZongheVo.B();
        fillDataByTiaoBao(allData(), ZongheVo.B.class, b);
        // b.setValue1("1.4万公里");
        // b.setValue2("1.4万公里");
        // b.setValue3("789");
        // b.setValue4("789");
        // b.setValue5("6400公里");
        b.setValue6(getTianbaoValue("双城港口货物吞吐量").orElse("3.2"));
        b.setValue7(getTianbaoValue("双城客运量").orElse("3.1"));
        b.setValue8(getTianbaoValue("成渝双城经济圈2小时出行覆盖率").orElse("82.80"));

        fillFieldInfo(b, fieldMean);
        return Result.OK(b).apiInfo(fieldMean);
    }

    @ApiOperation("综合概览-西部陆海新通道")
    @GetMapping("xblhxtd")
    public Result<ZongheVo.C> xblhxtd() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-西部陆海新通道");
        ZongheVo.C c = new ZongheVo.C();
        fillDataByTiaoBao(allData(), ZongheVo.C.class, c);
        c.setValue8(getTianbaoValue("西部陆海新通道线路数").orElse("78"));
        c.setValue9(getTianbaoValue("西部陆海新通道货运量").orElse("202"));
        c.setValue10(getTianbaoValue("西部陆海新通道海铁联运率").orElse("85"));
        c.setValue11(getTianbaoValue("西部陆海新通道货运同比增长率").orElse("13.8"));
        return Result.OK(c).apiInfo(fieldMean);
    }

    @ApiOperation("综合概览-基础设施")
    @GetMapping("jscs")
    public Result<ZongheVo.D> jscs() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-基础设施");
        ZongheVo.D d = new ZongheVo.D();
        fillDataByTiaoBao(allData(), ZongheVo.D.class, d);
        // d.setValue14("2.257281553");
        // d.setValue15("2.463845742");
        // d.setValue16("8.087841457");
        // d.setValue17("89.4483128");
        // d.setValue18("4472");
        // d.setValue56("33.90776699");
        // d.setValue57("12.41504854");
        // d.setValue58("21.49271845");
        // d.setValue59("2794");

        String v1 = getTianbaoValue("江北机场在飞国内航线条数").orElse("0");
        String v2 = getTianbaoValue("江北机场在飞国际（地区）航线条数").orElse("0");
        String v3 = getTianbaoValue("万州机场在飞国内航线条数").orElse("0");
        String v4 = getTianbaoValue("黔江机场在飞国内航线条数").orElse("0");
        String v5 = getTianbaoValue("巫山机场在飞国内航线条数").orElse("0");
        String v6 = getTianbaoValue("仙女山机场在飞国内航线条数").orElse("0");
        d.setValue75(NumberUtil.add(v1, v2, v3, v4, v5, v6).toString());

        Result<ShuiluVo.A> cb = shuiluApi.cb();
        d.setValue22(cb.getResult().getValue6());

        fillFieldInfo(d, fieldMean);
        return Result.OK(d).apiInfo(fieldMean);
    }

    @ApiOperation("综合概览-公共交通")
    @GetMapping("ggjt")
    public Result<ZongheVo.F> ggjt() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-公共交通");

        ZongheVo.F f = new ZongheVo.F();
        fillDataByTiaoBao(allData(), ZongheVo.F.class, f);
        // f.setValue23("41348辆");
        // f.setValue27("7895辆");
        // f.setValue28("338辆");

        String    json      = bwtJkzb();
        JSONArray jsonArray = JSONArray.parse(json);
        f.setValue23(getValue(jsonArray, "全市网约出租车实时在线数", "-"));
        f.setValue24(getValue(jsonArray, "中心城区巡游出租车行业稳定度", "-"));
        f.setValue25(getValue(jsonArray, "中心城区网约出租车行业饱和度", "-"));
        f.setValue26(getValue(jsonArray, "中心城区公交平均车速", "-"));
        f.setValue27(getValue(jsonArray, "中心城区公交运营车辆数", "-"));

        f.setValue29(ObjectUtil.defaultIfNull(sjtbDbDao.s_zc_fb_03(), "-"));

        f.setValue28(getValue(jsonArray, "轨道交通运营车辆数", "-"));
        f.setValue30(getValue(jsonArray, "线网载客饱和度", "-"));
        f.setValue31(getValue(jsonArray, "站点客流饱和度", "-"));

        f.setValue32(ObjectUtil.defaultIfNull(sjtbDbDao.s_zc_fb_02(), "-"));

        return Result.OK(f).apiInfo(fieldMean);
    }

    @ApiOperation("综合概览-行业治理")
    @GetMapping("hyzl")
    public Result<ZongheVo.H> hyzl() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-行业治理");

        ZongheVo.H h = new ZongheVo.H();
        fillDataByTiaoBao(allData(), ZongheVo.H.class, h);
        // h.setValue42("5");
        // h.setValue48("95");
        h.setValue77(String.valueOf(sjtbDbDao.onlineCarNumSum()));

        return Result.OK(h).apiInfo(fieldMean);
    }

    @ApiOperation("综合概览-运输服务")
    @GetMapping("ysfw")
    public Result<ZongheVo.G> ysfw() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-运输服务");
        ZongheVo.G g = new ZongheVo.G();
        g.setValue32(new GG());
        g.setValue33(new GG());
        g.setValue34(new GG());
        g.setValue35(new GG());

        JSONObject pjsdhjtzs = sjtbDbDao.pjsdhjtzs();
        g.setValue49(ObjectUtil.defaultIfNull(pjsdhjtzs.getString("avgspeed"), "0"));
        g.setValue50(ObjectUtil.defaultIfNull(pjsdhjtzs.getString("traindex"), "0"));

        Integer liangjiangyouKyl = sjtbDbDao.liangjiangyouKyl("1");
        Integer sanxiaKyl        = sjtbDbDao.sanxiaKyl("1");
        g.setValue54(nullToZero(sanxiaKyl));
        g.setValue55(nullToZero(liangjiangyouKyl));

        return Result.OK(g).apiInfo(fieldMean);
    }

    @ApiOperation("综合概览-服务能力")
    @GetMapping("fwnl")
    public Result<ZongheVo.I> fwnl() {
        Map<String, Object> fieldMean = new LinkedHashMap<>();
        fieldMean.put("title", "综合概览-服务能力");

        ZongheVo.I i = new ZongheVo.I();
        fillDataByTiaoBao(allData(), ZongheVo.I.class, i);
        // i.setValue62("4589");
        // i.setValue63("38.89");

        // i.setValue49("-");
        // i.setValue50("-");

        Integer liangjiangyouKyl = sjtbDbDao.liangjiangyouKyl("1");
        Integer sanxiaKyl        = sjtbDbDao.sanxiaKyl("1");

        i.setValue54(nullToZero(sanxiaKyl));
        i.setValue55(nullToZero(liangjiangyouKyl));

        return Result.OK(i).apiInfo(fieldMean);
    }

}
